package com.it.a01immutable;

import java.util.Iterator;
import java.util.List;

public class ImmutableDemo1 {
    public static void main(String[] args) {
        //创建不可变集合
        List<String> list = List.of("张三","李四","王五","赵六");

        System.out.println(list.get(0));
        System.out.println(list.get(1));
        System.out.println(list.get(2));
        System.out.println(list.get(3));

        System.out.println("------------");

        //增强for
        for(String s : list){
            System.out.println(s);
        }

        System.out.println("------------");

        Iterator<String> it = list.iterator();
        while(it.hasNext()){
            String name = it.next();
            System.out.println(name);
        }

        System.out.println("------------");

        for(int i = 0;i<list.size();i++){
            String name = list.get(i);
            System.out.println(name);
        }
    }
}
